#!/bin/bash

#/backup目录是存在的
mkdir  -p  /backup
#[ -d /backup ] || mkdir /backup
#备份的时间
backup_time=$(date +%Y%m%d%H%M%S)

#备份
tar  czf /backup/${backup_time}-log.tar.gz  /var/log   &>/dev/null
if (( $? == 0  ));then
	echo "$backup_time   $(hostname)  backup /backup/${backup_time}-log.tar.gz" |tee -a /var/log/backup_log.txt
fi

#删除7天前的文件
find  /backup  -mtime +7  -type f  -name "*-log.tar.gz"  -exec  rm  -rf  {} \;




